
const Koa = require('koa');
const path = require('path');
const static = require('koa-static');
const koaBody = require('koa-body');
const api = require('./api');
const compress = require('koa-compress');
const staticCache = require('koa-static-cache')
const redirectHtml = require('./middleware/redirectHtml');
// const authorization = require('./middleware/authorization'); // 验证登录
const args = require('minimist')(process.argv.slice(2));
const log = require('tools/log');
const uploadDir = path.join(__dirname, '../../files-temporary');
const maxFileSize = 5 * 1024 * 1024;

const app = new Koa();

app.use(koaBody({ multipart: true, formidable: { maxFileSize, uploadDir } }));
app.use(compress({ threshold: 1024 }));
app.use(api.whitelist.routes());
app.use(staticCache(path.join(__dirname, '../../web/dist'), { gzip: true }));
app.use(static(path.join(__dirname, '../../web/dist'), { gzip: true }));
app.use(static(path.join(__dirname, '../../files'), { gzip: true }));
// app.use(authorization);
// app.use(api.checklist.routes());
app.use(redirectHtml);
app.listen(args.WEB_PORT || '4100');

log(`http://localhost:${args.WEB_PORT || 4100}`);
log('数据库名称', args.MYSQL_NAME);
log('数据库密码', args.MYSQL_ROOT_PASSWORD);
log('数据库端口', args.MYSQL_PORT);
log('数据库IP', args.MYSQL_IP);
log('文件存储', uploadDir);
log('文件大小', maxFileSize / 1024 / 1024);
log('---------------------------------------------------');
